package com.liaoyifan.core.converter;

import com.liaoyifan.core.model.Page;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper(config = ConverterConfig.class)
public interface PageConverter {

    PageConverter INSTANCE = Mappers.getMapper(PageConverter.class);

    @SuppressWarnings("unchecked")
    static <T> Page<T> of(com.mybatisflex.core.paginate.Page<T> page) {
        return INSTANCE.convert(page);
    }

    @SuppressWarnings("rawtypes")
    @Mapping(source = "records", target = "list")
    @Mapping(source = "pageNumber", target = "current")
    @Mapping(source = "pageSize", target = "limit")
    @Mapping(source = "totalRow", target = "total")
    Page convert(com.mybatisflex.core.paginate.Page source);
}
